package cn.ylz.ylmall.product.dao.persist.repository.impl;

import cn.ylz.ylmall.product.dao.persist.mapper.PCommentMapper;
import cn.ylz.ylmall.product.dao.persist.repository.IPCommentRepository;
import cn.ylz.ylmall.product.pojo.entity.CommentLike;
import cn.ylz.ylmall.product.pojo.entity.PComment;
import cn.ylz.ylmall.product.pojo.vo.PCommentStandardVO;
import cn.ylz.ylmall.product.pojo.vo.PCommentVO;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class PCommentRepositoryImpl implements IPCommentRepository {
    @Autowired
    private PCommentMapper pCommentMapper;

    @Override
    public List<PCommentVO> listRootCommentByProductId(Long id) {
        return pCommentMapper.listRootComment(id);
    }

    @Override
    public List<PCommentVO> listByParentId(Long commentId) {
        return pCommentMapper.listByParentId(commentId);
    }

    @Override
    public int insert(PComment comment) {
        return pCommentMapper.insert(comment);
    }

    @Override
    public PCommentStandardVO getStandardById(Long commentId) {
        return pCommentMapper.getStandardById(commentId);
    }

    @Override
    public void deleteById(Long commentId) {
        pCommentMapper.deleteById(commentId);
    }

    @Override
    public List<Long> getLikedCommentsByUserAndProduct(Long productId, Long userId) {
        return pCommentMapper.getLikedCommentsByUserAndProduct(productId,userId);
    }

    @Override
    public void updateLikeCount(long commentId, long likeCount) {
        UpdateWrapper<PComment> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("comment_id", commentId)
                .set("like_count", likeCount);
        pCommentMapper.update(null, updateWrapper);
    }
}
